1 module directx.d3d12shader;
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 //  Copyright (c) Microsoft Corporation.  All rights reserved.
5 //
6 //  File:       D3D12Shader.h
7 //  Content:    D3D12 Shader Types and APIs
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 
11 version(Windows):
12 version(Direct3D_12):
13 
14 public import directx.d3dcommon;
15 
16 alias DWORD D3D12_SHADER_VERSION_TYPE;
17 enum : D3D12_SHADER_VERSION_TYPE
18 {
19     D3D12_SHVER_PIXEL_SHADER    = 0,
20     D3D12_SHVER_VERTEX_SHADER   = 1,
21     D3D12_SHVER_GEOMETRY_SHADER = 2,
22 
23     // D3D11 Shaders
24     D3D12_SHVER_HULL_SHADER     = 3,
25     D3D12_SHVER_DOMAIN_SHADER   = 4,
26     D3D12_SHVER_COMPUTE_SHADER  = 5,
27 
28     D3D12_SHVER_RESERVED0       = 0xFFF0,
29 }
30 
31 pure nothrow @safe @nogc {
32     DWORD D3D12_SHVER_GET_TYPE(DWORD _Version) {
33         return (_Version >> 16) & 0xffff;
34     }
35     DWORD D3D12_SHVER_GET_MAJOR(DWORD _Version) {
36         return (_Version >> 4) & 0xf;
37     }
38     DWORD D3D12_SHVER_GET_MINOR(DWORD _Version) {
39         return (_Version >> 0) & 0xf;
40     }
41 }
42 
43 // Slot ID for library function return
44 enum D3D_RETURN_PARAMETER_INDEX = (-1);
45 
46 alias D3D_RESOURCE_RETURN_TYPE D3D12_RESOURCE_RETURN_TYPE;
47 
48 alias D3D_CBUFFER_TYPE D3D12_CBUFFER_TYPE;
49 
50 struct D3D12_SIGNATURE_PARAMETER_DESC
51 {
52     LPCSTR                      SemanticName;   // Name of the semantic
53     UINT                        SemanticIndex;  // Index of the semantic
54     UINT                        Register;       // Number of member variables
55     D3D_NAME                    SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable
56     D3D_REGISTER_COMPONENT_TYPE ComponentType;  // Scalar type (e.g. uint, float, etc.)
57     BYTE                        Mask;           // Mask to indicate which components of the register
58     // are used (combination of D3D10_COMPONENT_MASK values)
59     BYTE                        ReadWriteMask;  // Mask to indicate whether a given component is
60     // never written (if this is an output signature) or
61     // always read (if this is an input signature).
62     // (combination of D3D_MASK_* values)
63     UINT                        Stream;         // Stream index
64     D3D_MIN_PRECISION           MinPrecision;   // Minimum desired interpolation precision
65 }
66 
67 struct D3D12_SHADER_BUFFER_DESC
68 {
69     LPCSTR                  Name;           // Name of the constant buffer
70     D3D_CBUFFER_TYPE        Type;           // Indicates type of buffer content
71     UINT                    Variables;      // Number of member variables
72     UINT                    Size;           // Size of CB (in bytes)
73     UINT                    uFlags;         // Buffer description flags
74 }
75 
76 struct D3D12_SHADER_VARIABLE_DESC
77 {
78     LPCSTR                  Name;           // Name of the variable
79     UINT                    StartOffset;    // Offset in constant buffer's backing store
80     UINT                    Size;           // Size of variable (in bytes)
81     UINT                    uFlags;         // Variable flags
82     LPVOID                  DefaultValue;   // Raw pointer to default value
83     UINT                    StartTexture;   // First texture index (or -1 if no textures used)
84     UINT                    TextureSize;    // Number of texture slots possibly used.
85     UINT                    StartSampler;   // First sampler index (or -1 if no textures used)
86     UINT                    SamplerSize;    // Number of sampler slots possibly used.
87 }
88 
89 struct D3D12_SHADER_TYPE_DESC
90 {
91     D3D_SHADER_VARIABLE_CLASS   Class;          // Variable class (e.g. object, matrix, etc.)
92     D3D_SHADER_VARIABLE_TYPE    Type;           // Variable type (e.g. float, sampler, etc.)
93     UINT                        Rows;           // Number of rows (for matrices, 1 for other numeric, 0 if not applicable)
94     UINT                        Columns;        // Number of columns (for vectors & matrices, 1 for other numeric, 0 if not applicable)
95     UINT                        Elements;       // Number of elements (0 if not an array)
96     UINT                        Members;        // Number of members (0 if not a structure)
97     UINT                        Offset;         // Offset from the start of structure (0 if not a structure member)
98     LPCSTR                      Name;           // Name of type, can be NULL
99 }
100 
101 alias D3D12_TESSELLATOR_DOMAIN = D3D_TESSELLATOR_DOMAIN;
102 
103 alias D3D12_TESSELLATOR_PARTITIONING = D3D_TESSELLATOR_PARTITIONING;
104 
105 alias D3D12_TESSELLATOR_OUTPUT_PRIMITIVE = D3D_TESSELLATOR_OUTPUT_PRIMITIVE;
106 
107 struct D3D12_SHADER_DESC
108 {
109     UINT                    Version;                     // Shader version
110     LPCSTR                  Creator;                     // Creator string
111     UINT                    Flags;                       // Shader compilation/parse flags
112 
113     UINT                    ConstantBuffers;             // Number of constant buffers
114     UINT                    BoundResources;              // Number of bound resources
115     UINT                    InputParameters;             // Number of parameters in the input signature
116     UINT                    OutputParameters;            // Number of parameters in the output signature
117 
118     UINT                    InstructionCount;            // Number of emitted instructions
119     UINT                    TempRegisterCount;           // Number of temporary registers used
120     UINT                    TempArrayCount;              // Number of temporary arrays used
121     UINT                    DefCount;                    // Number of constant defines
122     UINT                    DclCount;                    // Number of declarations (input + output)
123     UINT                    TextureNormalInstructions;   // Number of non-categorized texture instructions
124     UINT                    TextureLoadInstructions;     // Number of texture load instructions
125     UINT                    TextureCompInstructions;     // Number of texture comparison instructions
126     UINT                    TextureBiasInstructions;     // Number of texture bias instructions
127     UINT                    TextureGradientInstructions; // Number of texture gradient instructions
128     UINT                    FloatInstructionCount;       // Number of floating point arithmetic instructions used
129     UINT                    IntInstructionCount;         // Number of signed integer arithmetic instructions used
130     UINT                    UintInstructionCount;        // Number of unsigned integer arithmetic instructions used
131     UINT                    StaticFlowControlCount;      // Number of static flow control instructions used
132     UINT                    DynamicFlowControlCount;     // Number of dynamic flow control instructions used
133     UINT                    MacroInstructionCount;       // Number of macro instructions used
134     UINT                    ArrayInstructionCount;       // Number of array instructions used
135     UINT                    CutInstructionCount;         // Number of cut instructions used
136     UINT                    EmitInstructionCount;        // Number of emit instructions used
137     D3D_PRIMITIVE_TOPOLOGY  GSOutputTopology;            // Geometry shader output topology
138     UINT                    GSMaxOutputVertexCount;      // Geometry shader maximum output vertex count
139     D3D_PRIMITIVE           InputPrimitive;              // GS/HS input primitive
140     UINT                    PatchConstantParameters;     // Number of parameters in the patch constant signature
141     UINT                    cGSInstanceCount;            // Number of Geometry shader instances
142     UINT                    cControlPoints;              // Number of control points in the HS->DS stage
143     D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive;  // Primitive output by the tessellator
144     D3D_TESSELLATOR_PARTITIONING HSPartitioning;         // Partitioning mode of the tessellator
145     D3D_TESSELLATOR_DOMAIN  TessellatorDomain;           // Domain of the tessellator (quad, tri, isoline)
146     // instruction counts
147     UINT cBarrierInstructions;                           // Number of barrier instructions in a compute shader
148     UINT cInterlockedInstructions;                       // Number of interlocked instructions
149     UINT cTextureStoreInstructions;                      // Number of texture writes
150 }
151 
152 struct D3D12_SHADER_INPUT_BIND_DESC
153 {
154     LPCSTR                      Name;           // Name of the resource
155     D3D_SHADER_INPUT_TYPE       Type;           // Type of resource (e.g. texture, cbuffer, etc.)
156     UINT                        BindPoint;      // Starting bind point
157     UINT                        BindCount;      // Number of contiguous bind points (for arrays)
158 
159     UINT                        uFlags;         // Input binding flags
160     D3D_RESOURCE_RETURN_TYPE    ReturnType;     // Return type (if texture)
161     D3D_SRV_DIMENSION           Dimension;      // Dimension (if texture)
162     UINT                        NumSamples;     // Number of samples (0 if not MS texture)
163     UINT                        Space;          // Register space
164     UINT uID;                                   // Range ID in the bytecode
165 }
166 
167 enum D3D_SHADER_REQUIRES_DOUBLES = 0x00000001;
168 enum D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL = 0x00000002;
169 enum D3D_SHADER_REQUIRES_UAVS_AT_EVERY_STAGE = 0x00000004;
170 enum D3D_SHADER_REQUIRES_64_UAVS = 0x00000008;
171 enum D3D_SHADER_REQUIRES_MINIMUM_PRECISION = 0x00000010;
172 enum D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS = 0x00000020;
173 enum D3D_SHADER_REQUIRES_11_1_SHADER_EXTENSIONS = 0x00000040;
174 enum D3D_SHADER_REQUIRES_LEVEL_9_COMPARISON_FILTERING = 0x00000080;
175 enum D3D_SHADER_REQUIRES_TILED_RESOURCES = 0x00000100;
176 enum D3D_SHADER_REQUIRES_STENCIL_REF = 0x00000200;
177 enum D3D_SHADER_REQUIRES_INNER_COVERAGE = 0x00000400;
178 enum D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS = 0x00000800;
179 enum D3D_SHADER_REQUIRES_ROVS = 0x00001000;
180 enum D3D_SHADER_REQUIRES_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER = 0x00002000;
181 
182 struct D3D12_LIBRARY_DESC
183 {
184     LPCSTR    Creator;           // The name of the originator of the library.
185     UINT      Flags;             // Compilation flags.
186     UINT      FunctionCount;     // Number of functions exported from the library.
187 }
188 
189 struct D3D12_FUNCTION_DESC
190 {
191     UINT                    Version;                     // Shader version
192     LPCSTR                  Creator;                     // Creator string
193     UINT                    Flags;                       // Shader compilation/parse flags
194 
195     UINT                    ConstantBuffers;             // Number of constant buffers
196     UINT                    BoundResources;              // Number of bound resources
197 
198     UINT                    InstructionCount;            // Number of emitted instructions
199     UINT                    TempRegisterCount;           // Number of temporary registers used
200     UINT                    TempArrayCount;              // Number of temporary arrays used
201     UINT                    DefCount;                    // Number of constant defines
202     UINT                    DclCount;                    // Number of declarations (input + output)
203     UINT                    TextureNormalInstructions;   // Number of non-categorized texture instructions
204     UINT                    TextureLoadInstructions;     // Number of texture load instructions
205     UINT                    TextureCompInstructions;     // Number of texture comparison instructions
206     UINT                    TextureBiasInstructions;     // Number of texture bias instructions
207     UINT                    TextureGradientInstructions; // Number of texture gradient instructions
208     UINT                    FloatInstructionCount;       // Number of floating point arithmetic instructions used
209     UINT                    IntInstructionCount;         // Number of signed integer arithmetic instructions used
210     UINT                    UintInstructionCount;        // Number of unsigned integer arithmetic instructions used
211     UINT                    StaticFlowControlCount;      // Number of static flow control instructions used
212     UINT                    DynamicFlowControlCount;     // Number of dynamic flow control instructions used
213     UINT                    MacroInstructionCount;       // Number of macro instructions used
214     UINT                    ArrayInstructionCount;       // Number of array instructions used
215     UINT                    MovInstructionCount;         // Number of mov instructions used
216     UINT                    MovcInstructionCount;        // Number of movc instructions used
217     UINT                    ConversionInstructionCount;  // Number of type conversion instructions used
218     UINT                    BitwiseInstructionCount;     // Number of bitwise arithmetic instructions used
219     D3D_FEATURE_LEVEL       MinFeatureLevel;             // Min target of the function byte code
220     UINT64                  RequiredFeatureFlags;        // Required feature flags
221 
222     LPCSTR                  Name;                        // Function name
223     INT                     FunctionParameterCount;      // Number of logical parameters in the function signature (not including return)
224     BOOL                    HasReturn;                   // TRUE, if function returns a value, false - it is a subroutine
225     BOOL                    Has10Level9VertexShader;     // TRUE, if there is a 10L9 VS blob
226     BOOL                    Has10Level9PixelShader;      // TRUE, if there is a 10L9 PS blob
227 }
228 
229 struct D3D12_PARAMETER_DESC
230 {
231     LPCSTR                      Name;               // Parameter name.
232     LPCSTR                      SemanticName;       // Parameter semantic name (+index).
233     D3D_SHADER_VARIABLE_TYPE    Type;               // Element type.
234     D3D_SHADER_VARIABLE_CLASS   Class;              // Scalar/Vector/Matrix.
235     UINT                        Rows;               // Rows are for matrix parameters.
236     UINT                        Columns;            // Components or Columns in matrix.
237     D3D_INTERPOLATION_MODE      InterpolationMode;  // Interpolation mode.
238     D3D_PARAMETER_FLAGS         Flags;              // Parameter modifiers.
239 
240     UINT                        FirstInRegister;    // The first input register for this parameter.
241     UINT                        FirstInComponent;   // The first input register component for this parameter.
242     UINT                        FirstOutRegister;   // The first output register for this parameter.
243     UINT                        FirstOutComponent;  // The first output register component for this parameter.
244 }
245 
246 //////////////////////////////////////////////////////////////////////////////
247 // Interfaces ////////////////////////////////////////////////////////////////
248 //////////////////////////////////////////////////////////////////////////////
249 
250 mixin( uuid!(ID3D12ShaderReflectionType, "e913c351-783d-48ca-a1d1-4f306284ad56") );
251 extern (C++) interface ID3D12ShaderReflectionType : IUnknown
252 {
253     HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc);
254 
255     ID3D12ShaderReflectionType GetMemberTypeByIndex(UINT Index);
256     ID3D12ShaderReflectionType GetMemberTypeByName(LPCSTR Name);
257     LPCSTR GetMemberTypeName(UINT Index);
258 
259     HRESULT IsEqual(ID3D12ShaderReflectionType pType);
260     ID3D12ShaderReflectionType GetSubType();
261     ID3D12ShaderReflectionType GetBaseClass();
262     UINT GetNumInterfaces();
263     ID3D12ShaderReflectionType GetInterfaceByIndex(UINT uIndex);
264     HRESULT IsOfType(ID3D12ShaderReflectionType pType);
265     HRESULT ImplementsInterface(ID3D12ShaderReflectionType pBase);
266 }
267 
268 mixin( uuid!(ID3D12ShaderReflectionVariable, "8337a8a6-a216-444a-b2f4-314733a73aea") );
269 extern (C++) interface ID3D12ShaderReflectionVariable : IUnknown
270 {
271     HRESULT GetDesc(D3D12_SHADER_VARIABLE_DESC* pDesc);
272 
273     ID3D12ShaderReflectionType GetType();
274     ID3D12ShaderReflectionConstantBuffer GetBuffer();
275 
276     UINT GetInterfaceSlot(UINT uArrayIndex);
277 }
278 
279 mixin( uuid!(ID3D12ShaderReflectionConstantBuffer, "c59598b4-48b3-4869-b9b1-b1618b14a8b7") );
280 extern (C++) interface ID3D12ShaderReflectionConstantBuffer : IUnknown
281 {
282     HRESULT GetDesc(D3D12_SHADER_BUFFER_DESC* pDesc);
283 
284     ID3D12ShaderReflectionVariable GetVariableByIndex(UINT Index);
285     ID3D12ShaderReflectionVariable GetVariableByName(LPCSTR Name);
286 }
287 
288 mixin( uuid!(ID3D12ShaderReflection, "5a58797d-a72c-478d-8ba2-efc6b0efe88e") );
289 extern (C++) interface ID3D12ShaderReflection : IUnknown
290 {
291     HRESULT GetDesc(D3D12_SHADER_DESC* pDesc);
292 
293     ID3D12ShaderReflectionConstantBuffer GetConstantBufferByIndex(UINT Index);
294     ID3D12ShaderReflectionConstantBuffer GetConstantBufferByName(LPCSTR Name);
295 
296     HRESULT GetResourceBindingDesc(UINT ResourceIndex,
297                                    D3D12_SHADER_INPUT_BIND_DESC* pDesc);
298 
299     HRESULT GetInputParameterDesc(UINT ParameterIndex,
300                                   D3D12_SIGNATURE_PARAMETER_DESC* pDesc);
301     HRESULT GetOutputParameterDesc(UINT ParameterIndex,
302                                    D3D12_SIGNATURE_PARAMETER_DESC* pDesc);
303     HRESULT GetPatchConstantParameterDesc(UINT ParameterIndex,
304                                           D3D12_SIGNATURE_PARAMETER_DESC* pDesc);
305 
306     ID3D12ShaderReflectionVariable GetVariableByName(LPCSTR Name);
307 
308     HRESULT GetResourceBindingDescByName(LPCSTR Name,
309                                          D3D12_SHADER_INPUT_BIND_DESC* pDesc);
310 
311     UINT GetMovInstructionCount();
312     UINT GetMovcInstructionCount();
313     UINT GetConversionInstructionCount();
314     UINT GetBitwiseInstructionCount();
315 
316     D3D_PRIMITIVE GetGSInputPrimitive();
317     BOOL IsSampleFrequencyShader();
318 
319     UINT GetNumInterfaceSlots();
320     HRESULT GetMinFeatureLevel(D3D_FEATURE_LEVEL* pLevel);
321 
322     UINT GetThreadGroupSize(
323         UINT* pSizeX,
324         UINT* pSizeY,
325         UINT* pSizeZ);
326 
327     UINT64 GetRequiresFlags();
328 }
329 
330 mixin( uuid!(ID3D12LibraryReflection, "8e349d19-54db-4a56-9dc9-119d87bdb804") );
331 extern (C++) interface ID3D12LibraryReflection : IUnknown
332 {
333     HRESULT GetDesc(D3D12_LIBRARY_DESC* pDesc);
334 
335     ID3D12FunctionReflection GetFunctionByIndex(INT FunctionIndex);
336 }
337 
338 mixin( uuid!(ID3D12FunctionReflection, "1108795c-2772-4ba9-b2a8-d464dc7e2799") );
339 extern (C++) interface ID3D12FunctionReflection : IUnknown
340 {
341     HRESULT GetDesc(D3D12_FUNCTION_DESC * pDesc);
342 
343     ID3D12ShaderReflectionConstantBuffer GetConstantBufferByIndex(UINT BufferIndex);
344     ID3D12ShaderReflectionConstantBuffer GetConstantBufferByName(LPCSTR Name);
345 
346     HRESULT GetResourceBindingDesc(UINT ResourceIndex,
347                                    D3D12_SHADER_INPUT_BIND_DESC* pDesc);
348 
349     ID3D12ShaderReflectionVariable GetVariableByName(LPCSTR Name);
350 
351     HRESULT GetResourceBindingDescByName(LPCSTR Name,
352                                          D3D12_SHADER_INPUT_BIND_DESC* pDesc);
353 
354     // Use D3D_RETURN_PARAMETER_INDEX to get description of the return value.
355     ID3D12FunctionParameterReflection GetFunctionParameter(INT ParameterIndex);
356 };
357 
358 mixin( uuid!(ID3D12FunctionParameterReflection, "ec25f42d-7006-4f2b-b33e-02cc3375733f") );
359 extern (C++) interface ID3D12FunctionParameterReflection : IUnknown
360 {
361     HRESULT GetDesc(D3D12_PARAMETER_DESC* pDesc);
362 }